const Koa = require('koa');
const app = new Koa();


// 日志中间件
app.use(async (ctx, next) => {
    const start = Date.now();
    await next(); // 调用下一个中间件
    console.log("执行了日志中间件");
    
    const ms = Date.now() - start;
    console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
  });
  
  // 响应中间件
  app.use(async (ctx,next) => {
    ctx.body = '1-2Hello, Koa!';
    console.log('执行了aaa');
    await next();
    console.log('执行了aaa-1');

    
  });

  app.use(async (ctx) => {
    ctx.body = '1-3Hello, Koa!';
    console.log('执行了bbb');
  });

let port =5008
// 启动服务器
app.listen(port, () => {
  console.log(`Server is running at ${port}`);
});